package com.hnevc.mallserver3.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;

import com.hnevc.mallserver3.dto.CartDTO;
import com.hnevc.mallserver3.dto.CommentDTO;
import com.hnevc.mallserver3.dto.Page;
import com.hnevc.mallserver3.entity.Comment;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface CommentMapper extends BaseMapper<Comment> {
    // 这里可以添加一些非通用的方法
    @Select("SELECT co.id as id, co.member_id as member_id,co.goods_id as goods_id, g.goods_name as goods_name, g.icon as icon , co.comment as comment, m.username as username, co.postdate as postdate " +
            "FROM t_comment co JOIN t_goods g ON co.goods_id = g.id" +
            " JOIN t_member m ON co.member_id = m.id  " +
            "WHERE co.id = #{id} Order By co.id desc")
    List<CommentDTO> selectCommentItemsById(@Param("id") Long id);
    // 这里可以添加一些非通用的方法
    @Select("SELECT co.id as id, co.member_id as member_id,co.goods_id as goods_id, g.goods_name as goods_name, g.icon as icon , co.comment as comment, m.username as username, co.postdate as postdate " +
            "FROM t_comment co JOIN t_goods g ON co.goods_id = g.id" +
            " JOIN t_member m ON co.member_id = m.id  " +
            "WHERE g.id = #{id}  Order By co.id desc")
    List<CommentDTO> selectCommentItemsByGoodsId(@Param("id") Long id);
    @Select("SELECT co.id as id, co.member_id as member_id,co.goods_id as goods_id, g.goods_name as goods_name, g.icon as icon , co.comment as comment, m.username as username, co.postdate as postdate " +
            "FROM t_comment co JOIN t_goods g ON co.goods_id = g.id" +
            " JOIN t_member m ON co.member_id = m.id  " +
            "WHERE g.id = #{id} Order By co.id desc limit #{from}, #{size}")
    List<CommentDTO> selectCommentItemsByGoodsIdByPage(@Param("id") Long id, @Param("from") Long from,@Param("size") Long size);
}